package com.donzell.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import com.donzell.joinmodel.AdminUser;
import com.donzell.model.EcsAdminUser;


public interface AdminUserDao extends JpaRepository<EcsAdminUser, Long> {
//    @Query(value="select id,account from User where id=1")
//	public EcsAdminUser getAAA();
      
	
	
	  String sql = "select new  com.donzell.joinmodel.AdminUser(u.userId,u.userName, u.email, u.phone, u.addTime, u.lastLogin, u.lastIp, r.roleName, u.isUse) "  
            + "from  EcsAdminUser u,EcsRole r where r.roleId = u.roleId";  
	  @Query(sql) 
	  List<AdminUser> getAllUsers(); 
	
	  @Query("select u from EcsAdminUser u where u.userName = :userName") 
	  EcsAdminUser findByUserName(@Param("userName") String userName); 
    
	  @Query("select count(u) from EcsAdminUser u where userName = :userName")
	  Integer findAdminUserNumberByUserName(@Param("userName") String userName);
	  
	  Long countByUserName(String userName);
	  
	  @Transactional
	  @Modifying(clearAutomatically = true)
	  @Query("update EcsAdminUser u set u.isUse = :isUse where u.userId = :userId")
	  public int updateIsUse(@Param(value = "userId") Short userId,@Param(value = "isUse") Short isUse);
	  
}